/*     */ package com.kendoui.taglib.html;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import java.io.StringWriter;
/*     */ import java.io.Writer;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ 
/*     */ public abstract class Element<T extends Element<T>>
/*     */   implements Node
/*     */ {
/*     */   private String tagName;
/*     */   private boolean selfClosing;
/*     */   private List<Node> children;
/*     */   private Map<String, Object> attributes;
/*     */   private String innerHtml;
/*     */ 
/*     */   protected Element(String tagName)
/*     */   {
/*  21 */     this(tagName, false);
/*     */   }
/*     */ 
/*     */   protected Element(String tagName, boolean selfClosing) {
/*  25 */     this.children = new ArrayList();
/*  26 */     this.innerHtml = "";
/*  27 */     this.tagName = tagName;
/*  28 */     this.selfClosing = selfClosing;
/*  29 */     this.attributes = new HashMap();
/*     */   }
/*     */ 
/*     */   public T append(Node child)
/*     */   {
/*  34 */     this.children.add(child);
/*     */ 
/*  36 */     return (T) this;
/*     */   }
/*     */ 
/*     */   public T text(String text) {
/*  40 */     return html(Text.escapeHtml(text));
/*     */   }
/*     */ 
/*     */   public T html(String html)
/*     */   {
/*  45 */     this.innerHtml = html;
/*     */ 
/*  47 */     this.children.clear();
/*     */ 
/*  49 */     return (T) this;
/*     */   }
/*     */ 
/*     */   public String html() {
/*  53 */     return this.innerHtml;
/*     */   }
/*     */ 
/*     */   public T attr(String attribute, Object value)
/*     */   {
/*  58 */     this.attributes.put(attribute, value);
/*     */ 
/*  60 */     return (T) this;
/*     */   }
/*     */ 
/*     */   public void write(Writer out) throws IOException {
/*  64 */     out.append("<").append(this.tagName);
/*     */ 
/*  67 */     for (Map.Entry attribute : this.attributes.entrySet()) {
/*  68 */       out.append(" ").append((CharSequence)attribute.getKey()).append("=\"").append(attribute.getValue().toString()).append("\"");
/*     */     }
/*     */ 
/*  75 */     if (this.selfClosing) {
/*  76 */       out.append(" />");
/*     */     } else {
/*  78 */       out.append(">");
/*     */ 
/*  80 */       writeContent(out);
/*     */ 
/*  82 */       out.append("</").append(this.tagName).append(">");
/*     */     }
/*     */   }
/*     */ 
/*     */   private void writeContent(Writer out)
/*     */     throws IOException
/*     */   {
/*  89 */     if (!this.innerHtml.isEmpty()) {
/*  90 */       out.write(this.innerHtml);
/*     */     }
/*     */ 
/*  93 */     for (Node child : this.children)
/*  94 */       child.write(out);
/*     */   }
/*     */ 
/*     */   public String outerHtml() throws IOException
/*     */   {
/*  99 */     StringWriter out = new StringWriter();
/*     */ 
/* 101 */     write(out);
/*     */ 
/* 103 */     return out.toString();
/*     */   }
/*     */ }

/* Location:           D:\Liao\kendoui.jsp.2013.1.319.trial\wrappers\jsp\kendo-taglib\kendo-taglib-2013.1.319.jar
 * Qualified Name:     com.kendoui.taglib.html.Element
 * JD-Core Version:    0.6.2
 */